package fm.last.api
{
    import flash.net.URLRequestMethod;
    import flash.net.URLVariables;
    
    import fm.last.Agent;
    import fm.last.RestAPI;
    import fm.last.error.AuthError;
    
    final public class AuthAPI extends RestAPI
    {
        // those in comment are not implemented
//        public static const AUTH_GET_MOBILE_SESSION:String = "auth.getMobileSession";
        public static const AUTH_GET_SESSION:String        = "auth.getSession";
//        public static const AUTH_GET_TOKEN:String          = "auth.getToken";
//        public static const AUTH_GET_WEB_SESSION:String    = "auth.getWebSession";

        
        public function AuthAPI(agent:Agent)
        {
            super(agent);
        }

        /* ********************************************************************/
        
        public function getSession(onComplete:Function,
                                   onError:Function, 
                                   token:String):void
        {
            if (token == null) {
                throw new AuthError("TOKEN is necessary to get session!");
            }
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = AuthAPI.AUTH_GET_SESSION;
            urlVars["token"] = token;            
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);
        }
        
        
    }
}